package com.wwz.service;

import com.wwz.dao.ProductDao;
import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductDao productDao;

    @Override
    public int update(String name,Integer id){
        return productDao.update(name,id);
    }

    @Override
    public boolean commit(BusinessActionContext businessActionContext) {
        return true;
    }

    @Override
    public boolean rollback(BusinessActionContext businessActionContext) {
        try{
            String productId = businessActionContext.getActionContext().get("productId")+"";
            String productNum = businessActionContext.getActionContext().get("productNum")+"";
           productDao.updateNum(productNum,Long.parseLong(productId));
           return true;
        }catch (Exception e){
            e.printStackTrace();
        }
        return false;
    }
}
